package Keyword.StaticDemo;


public class A {
    private int x = 1;         // 实例变量
    private static int y = 2;  // 静态变量

    public static void func1() {
        int b = y;  // Non-static field 'y' cannot be referenced from a static context
//        int b = this.y;     // 'A.this' cannot be referenced from a static context
    }

    public static void main(String[] args) {
        /* 不能直接从静态方法中访问一个实例变量，因为实例变量需要依赖于具体的对象实例才能存在，而静态方法或变量则属于类本身，不依赖于任何对象实例。 */
//         int x = A.x;  // Non-static field 'x' cannot be referenced from a static context
        A a = new A();
        int x = a.x;
        int y = A.y;
        System.out.println(x + " " + y);
    }
}

